/**
 *
 * Copyright Pact Lab of H.I.T.
 *
 * Designed and Implemented by Grid Researching Group, 
 * Pact Lab, Harbin
 * 
 * This Project is part of the national 973 Project:
 * Internet Based Virtual Computing Environment
 *
 * http://pact518.hit.edu.cn
 * 
 * Author:       Meteor <meteorlxk@gmail.com> 
 * Copyright:    pact518 
 * Version:      1.0
 * Created:      2008-12-15 
 * LastModified: 2008-12-15
 */
package edu.hit.pact.pgse.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Meteor
 *
 */
public class ChineseCharEncode {
    private static final String regEx = "[\\u4e00-\\u9fa5]";
    private static final Pattern p = Pattern.compile(regEx);
    private static final String charset = "UTF-8";
    
    public static synchronized String encode(String line){	
		Matcher m = p.matcher(line);
		
		while (m.find()) {
			try {
				String temp = URLEncoder.encode(m.group(0), charset);
				line = line.replaceAll(m.group(0), temp);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}//if while
		
		return line;
    }
}
